home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************
-
- main.c
-
- This file contains the main code, initialization routines, and
- an override for gxPrintingEvent for the QuickDraw GX aware
- sample, "Simple Sample GX."
-
- Additional info can be found in the related develop #19 article,
- "Adding QuickDraw GX Printing to QuickDraw Applications."
-
- Dave Hersey, Apple Developer Technical Support.
-
- ——————— Edit Trail ———————
-
- creation: 1/22/94 - dmh
- cleaned up for 2nd draft of develop article: 3/10/94 - dmh
- cleaned up for final: 4/14/94 - dmh
-
- *********************************************************************/
-
- #include "Simple Sample.h"
-
- Rect gWindowRect = {50, 15, 512, 510}; // Our window size.
- short gAppResRefNum; // Our app's resource file refNum.
- long gSleep = 0; // Sleep value for WaitNextEvent.
- Boolean gQuitAfterPrinting = true; // Quit after handling 'pdoc'?
- Boolean gQuitting; // Quitting?
- Boolean gSystemSevenIsPresent; // System 7.0 or later is available?
- Boolean gGXIsPresent; // Using QuickDraw GX is available?
- Boolean gInPrintDialog; // Is a QDGX print dialog displayed?
- gxGraphicsClient gClient; // Our app's QDGX graphics client.
-
-
- /************************************************************
- MyInitialize - This routine performs the standard Mac
- toolbox initialization.
-
- *************************************************************/
-
- void MyInitialize()
- {
- CursHandle theCurs;
- Handle menuBar;
-
- // We're not quitting, and we don't have a print dialog displayed.
-
- gQuitting = false;
- gInPrintDialog = false;
-
- // Initialize.
-
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitCursor();
-
- /*
- See what system software is available. If we don't have
- what we need, bail.
- */
- MyCheckConfig();
-
- if (!gSystemSevenIsPresent)
- {
- Alert(r_BadConfig, nil);
- gQuitting = true;
- return;
- }
-
- /*
- Change to a watch cursor while we set up our menu bar
- and then install our AppleEvent handlers.
- */
- theCurs = GetCursor(watchCursor);
- SetCursor(*theCurs);
-
- menuBar = GetNewMBar(rMenuBar);
-
- if (menuBar)
- {
- SetMenuBar(menuBar);
- DisposHandle(menuBar);
- AddResMenu(GetMHandle(mApple), 'DRVR');
- DrawMenuBar();
- SetCursor(&qd.arrow);
-
- MyDoAEInstallation();
- }
- }
-
-
- /************************************************************
- MyCheckConfig - This routine sets up our global
- configuration variables based on results from Gestalt.
-
- *************************************************************/
-
- void MyCheckConfig()
- {
- long sysVersion;
-
- // Get the system version and see if it's 7.0 or later.
-
- gSystemSevenIsPresent = false;
-
- if (Gestalt(gestaltSystemVersion, &sysVersion) == noErr)
- if (sysVersion >= 0x0700) gSystemSevenIsPresent = true;
- }
-
-
- /************************************************************
- MyInitGXIfPresent - This routine checks to see if the
- QuickDraw GX graphics and printing routines are available,
- and if so, initializes them for us.
-
- *************************************************************/
-
- void MyInitGXIfPresent()
- {
- long gxVersion, gxPrintVersion;
- MenuHandle fileMenu;
-
- // Assume GX is NOT present, and then check to see if it is.
-
- gGXIsPresent = false;
-
- if (Gestalt(gestaltGXVersion, &gxVersion) == noErr)
- if (Gestalt(gestaltGXPrintingMgrVersion, &gxPrintVersion) == noErr)
- gGXIsPresent = true;
-
- /*
- If QuickDraw GX is available, initialize it. Otherwise, remove
- the QuickDraw GX options from our File menu.
- */
- if (gGXIsPresent)
- {
- gClient = GXNewGraphicsClient(nil, kGraphicsHeapSize, (gxClientAttribute) 0);
- GXEnterGraphics();
- GXInitPrinting();
- }
- else
- {
- fileMenu = GetMHandle(mFile);
- DelMenuItem(fileMenu, iPrintOneCopy);
- DelMenuItem(fileMenu, iCustomPageSetup);
- }
- }
-
-
- /************************************************************
- MyCleanUpGXIfPresent - This routine de-installs the
- QuickDraw GX graphics and printing routines, if we
- initialized them earlier.
-
- *************************************************************/
-
- void MyCleanUpGXIfPresent()
- {
- if (gGXIsPresent)
- {
- GXExitPrinting();
- GXDisposeGraphicsClient(gClient);
- GXExitGraphics();
- }
- }
-
-
- /************************************************************
- MyPrintingEventOverride - This routine is an override for
- the gxPrintingEvent message. This routine is passed
- control when the movable modal print dialogs are displayed
- and we need to update our windows.
-
- *************************************************************/
-
- OSErr MyPrintingEventOverride(EventRecord *anEvent, Boolean filterEvent)
- {
-
- /*
- Handle events in whatever way is appropriate. MyDoEvent is our
- generic event handler. We don't pass it events that it shouldn't
- handle while print dialogs are displayed.
- */
- if (!filterEvent)
- switch (anEvent->what)
- {
- case mouseDown:
- case keyDown:
- case autoKey:
- break;
-
- default:
- MyDoEvent(anEvent);
- }
-
- return noErr;
- }
-
-
- /************************************************************
- main - This is our main routine. Not much else to say…
-
- *************************************************************/
-
- void main()
- {
- WindowPtr wind;
- char i;
-
- gAppResRefNum = CurResFile();
- MaxApplZone();
- for (i = 1; i <= 6; i++)
- MoreMasters();
-
- // Initialize the managers and jump into our event loop.
-
- MyInitialize();
- MyInitGXIfPresent();
-
- while (!gQuitting)
- MyEventLoop();
-
- // Leaving. Close all the windows we opened and tear down GX.
-
- while (wind = FrontWindow())
- MyDisposeDocument(MyGetDocPtr(wind));
-
- MyCleanUpGXIfPresent();
- }
-